package com.gm.wholesale.module.order.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.ListView;

import androidx.annotation.Nullable;

import com.gm.commonlib.base.baseAdapter.CommonAdapter;
import com.gm.commonlib.base.baseAdapter.ViewHolder;
import com.gm.commonlib.views.popupwindow.Popupwindow2;
import com.gm.wholesale.R;
import com.gm.wholesale.module.unit.bean.UnitBean;

import java.util.List;

public class ChoiceUnitView extends LinearLayout {
    private Context mContext;
    private ListView listView;
    private OnChoiceUnitListener mListener;

    public void setOnChoiceUnitListener(OnChoiceUnitListener listener){
        this.mListener=listener;
    }
    public interface OnChoiceUnitListener{
        void choiceUnit(UnitBean unitBean);
    }

    public ChoiceUnitView(Context context) {
        super(context);
        initView(context);
    }

    public ChoiceUnitView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        mContext = context;
        LayoutInflater.from(context).inflate(R.layout.view_pop_choice_unit, this);

        listView = findViewById(R.id.listView);

    }

    public void showView(List<UnitBean> unitBeans){
        listView.setAdapter(new CommonAdapter<>(mContext, unitBeans, R.layout.list_item_unit) {

            @Override
            public void convert(ViewHolder var1, UnitBean var2) {
                var1.setText(R.id.unitTv, var2.getName());
                var1.getConvertView().setOnClickListener(view -> {
                    Popupwindow2.hiddenPop();
                    mListener.choiceUnit(var2);
                });
            }
        });
    }
}
